﻿Imports System.Net
Imports System.IO
Imports System.Text
Imports System.Xml

Public Class search
    Dim result(1, 4) As String
    Public Function searchyige(ByVal query As String)
        Dim req As HttpWebRequest = WebRequest.Create("http://search.1g1g.com/public/songs?encoding=utf8&query" + query)
        Dim res As HttpWebResponse = req.GetResponse()
        Dim strm As StreamReader = New StreamReader(res.GetResponseStream(), Encoding.UTF8)
        Dim sline As String
        sline = strm.ReadToEnd()

        xmljx(sline)
        MsgBox(result(1, 1) & result(1, 2))
        Return result
    End Function

    Public Sub xmljx(ByVal query)

        Dim node As XmlNode = Me.nodeXml(query)(0).ChildNodes.Item(1)
        ReDim result(node(query)(0).ChildNodes.Count, 4)
        Dim results = -1
        Dim results2 = -1
        For Each element As XmlElement In node
            results += 1
            Dim node2 As XmlNode = Me.nodeXml(query)(0).ChildNodes.Item(1).Item(results)
            For Each elements As XmlElement In node2
                results2 += 1
                Dim node3 As XmlNode = Me.nodeXml(query)(0).ChildNodes.Item(1).Item(results2)
                If element.GetAttribute("id") = "id" Then
                    result(results2, 0) = element.InnerText
                End If
                If element.GetAttribute("id") = "name" Then
                    result(results2, 1) = element.InnerText
                End If
                If element.GetAttribute("id") = "singer" Then
                    result(results2, 2) = element.InnerText
                End If
                If element.GetAttribute("id") = "slbum" Then
                    result(results2, 3) = element.InnerText
                End If
                If element.GetAttribute("id") = "uploaduser" Then
                    result(results2, 4) = element.InnerText
                End If
            Next
        Next
    End Sub

    Public Function nodeXml(ByVal s As String) As XmlNodeList
        Dim document As New XmlDocument()
        document.LoadXml(s)
        Return document.GetElementsByTagName("arguments")
    End Function
End Class
